<% layout('/layouts/default.html', {title: '编码规则管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('编码规则管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnReset" title="${text('重置当前编号')}"><i class="fa icon-reload"></i> ${text('重置当前编号')}</a>
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('custom:codeRule:edit')){ %>
					<a href="${ctx}/custom/codeRule/form" class="btn btn-default btnTool" title="${text('新增编码规则')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${codeRule}" action="${ctx}/custom/codeRule/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('单据类型')}：</label>
					<div class="control-inline width-120">
						<#form:select path="recordType" dictType="erp_record_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('前缀')}：</label>
					<div class="control-inline">
						<#form:input path="prefix" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('是否添加年月')}：</label>
					<div class="control-inline width-120">
						<#form:select path="yearFlag" dictType="sys_yes_no" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('初始编号')}：</label>
					<div class="control-inline">
						<#form:input path="initNumber" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('编号长度')}：</label>
					<div class="control-inline">
						<#form:input path="numberLength" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('当前编号')}：</label>
					<div class="control-inline">
						<#form:input path="currentNumber" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('备注信息')}：</label>
					<div class="control-inline">
						<#form:input path="remarks" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	showCheckbox: true,
	columnModel: [
		{header:'${text("单据类型")}', name:'recordType', index:'a.record_type', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/custom/codeRule/detail?id='+row.id+'" class="btnList" data-title="${text("编辑编码规则")}">'+js.getDictLabel(${@DictUtils.getDictListJson('erp_record_type')}, val, '${text("未知")}', true)+'</a>';
		}},
		{header:'${text("前缀")}', name:'prefix', index:'a.prefix', width:150, align:"left"},
		{header:'${text("是否添加年月")}', name:'yearFlag', index:'a.year_flag', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("未知")}', true);
		}},
		{header:'${text("初始编号")}', name:'initNumber', index:'a.init_number', width:150, align:"center"},
		{header:'${text("编号长度")}', name:'numberLength', index:'a.number_length', width:150, align:"center"},
		{header:'${text("当前编号")}', name:'currentNumber', index:'a.current_number', width:150, align:"center"},
		{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
		{header:'${text("备注信息")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:140, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
            <% if(hasPermi('custom:codeRule:view')){ %>
                actions.push('<a href="${ctx}/custom/codeRule/detail?id='+row.id+'" class="btnList" title="${text("查看编码规则")}"><i class="fa fa-file-text-o"></i></a>&nbsp;');
            <% } %>
			<% if(hasPermi('custom:codeRule:edit')){ %>
				actions.push('<a href="${ctx}/custom/codeRule/form?id='+row.id+'" class="btnList" title="${text("编辑编码规则")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/custom/codeRule/delete?id='+row.id+'" class="btnList" title="${text("删除编码规则")}" data-confirm="${text("确认要删除该编码规则吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script>
	// 重置编号
	$("#btnReset").on("click", function () {
		let arr = $('#dataGrid').dataGrid('getSelectRows');
		if (arr.length > 0) {
			js.confirm("确认要重置所选单据的编号吗？",
					{
						url: "${ctx}/custom/codeRule/reset",
						traditional: true,
						data: {"ids": arr},
						callback: function (data) {
							js.showMessage(data.message);
						},
						dataType: "json",
						async: false,
						message: "正在重置...",
						shadeClose: true
					});
		} else {
			js.showErrorMessage("请选择需要重置的单据")
		}
	});
</script>